package com.sui.bigdata.rtcadmin.repository.mapper;

import com.sui.bigdata.rtcadmin.repository.model.ResourceInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author: TingWuHuang
 * @Date: 2020/7/2 14:47
 * @description
 */
@Mapper
@Component
public interface ResourceInfoMapper {

    @Insert("insert into resource_info(file_name,file_path,resource,file_size,remarks) " +
            "values(#{fileName},#{filePath},#{resource},#{fileSize},#{remarks})")
    void insert(ResourceInfo resourceInfo);

    @Update("update resource_info set is_delete = 1 where file_name = #{fileName} ")
    void delete(String fileName);

    @Update("update resource_info set file_path=#{filePath},resource=#{resource},file_size=#{fileSize},remarks=#{remarks}" +
            " where file_name = #{fileName} ")
    void update(ResourceInfo resourceInfo);

    @Select("<script>"
            + "select * from resource_info where is_delete = 0 "
            + "<if test='fileName != null'>"
            + "and file_name = #{fileName} "
            + "</if>"
            + "<if test='resource != null'>"
            + "and resource = #{resource} "
            + "</if>"
            + "</script>")
    @ResultType(ResourceInfo.class)
    List<ResourceInfo> select(ResourceInfo resourceInfo);

    @Select("select * from resource_info where file_name = #{fileName}")
    @ResultType(ResourceInfo.class)
    ResourceInfo selectByFileName(String fileName);

}
